// Example that shows simple usage of the INIReader class
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <sstream>
#include "INIReader.h"
#include "cstdio"

std::string sections(INIReader& reader)
{
    std::stringstream ss;
    std::set<std::string> sections = reader.Sections();
    for (std::set<std::string>::iterator it = sections.begin(); it != sections.end(); ++it)
        ss << *it << ",";
    return ss.str();
}
class fh8626_ini_section 
{
public:
    fh8626_ini_section(const std::string& name)
    {
        this->sec_name =name;
    }


    std::string sec_name;
    std::string     file;
    std::string     ImageName;
    std::string   FlashAddress;
};

int main(int argc ,char* argv[])
{
    if(argc==2){
        
    }else{
        std::cout <<"Input file name !\n";
        return -1;
    }
    INIReader reader(argv[1]);

    if (reader.ParseError() < 0) {
        std::cout << "Can't load 'test.ini'\n";
        return 1;
    }
    std::cout << "Config loaded from 'test.ini': found sections=" << sections(reader);

        // << " version="
        // << reader.GetInteger("protocol", "version", -1) << ", name="
        // << reader.Get("user", "name", "UNKNOWN") << ", email="
        // << reader.Get("user", "email", "UNKNOWN") << ", multi="
        // << reader.Get("user", "multi", "UNKNOWN") << ", pi="
        // << reader.GetReal("user", "pi", -1) << ", active="
        // << reader.GetBoolean("user", "active", true) << "\n";


    fh8626_ini_section  code3("code3");

    fh8626_ini_section code4("code4");
    fh8626_ini_section code5("code5");
    auto printCode= [&](fh8626_ini_section& code){
        std::cout<<"code:" << code.sec_name <<"\n"
            <<"file:"<<code.file<<"\n"
            <<"ImageName:"<<code.ImageName<<"\n"
            <<"FlashAddress:"<<code.FlashAddress<<"\n";
    };

    auto readCode= [&](fh8626_ini_section& code){
        code.FlashAddress= reader.Get(code.sec_name, "FlashAddress", "UNKNOWN");
        code.file= reader.Get(code.sec_name, "FilePath", "UNKNOWN");
        code.ImageName= reader.Get(code.sec_name, "ImageName","UNKNOWN");
        printCode(code);

    };
   
    readCode(code3);
    readCode(code4);
    readCode(code5);




    return 0;
}
